package 竞赛.NO_398;

/**
 * 描述：
 *
 * @author lanran
 * @date 2024/5/19 11:10
 **/
public class 所有数对中数位不同之和_100300 {
    public static void main(String[] args) {
        Solution s = new Solution();
        System.out.println(s.sumDigitDifferences(new int[]{50, 28, 48}));
    }

    static class Solution {
        public long sumDigitDifferences(int[] nums) {
            int[][] count = new int[10][10];
            for (int i = 0; i < nums.length; i++) {
                int x = nums[i];
                for (int k = 0; k < 10; k++) {
                    count[k][x % 10]++;
                    x /= 10;
                }
            }
            long ans = 0;
            for (int i = 0; i < 10; i++) {
                for (int k = 0; k < 10; k++) {
                    long s = count[i][k];
                    s = s * (nums.length - s);
                    ans += s;
                }
            }
            return ans / 2;
        }
    }
}
